local joyex__qizhi = fk.CreateSkill {

  name = "joyex__qizhi",

  tags = {  },

}



joyex__qizhi:addEffect(fk.TargetSpecified, {
  name = "joyex__qizhi",
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joyex__qizhi.name) and player.phase ~= Player.NotActive and
      data.firstTarget and data.card.type ~= Card.TypeEquip
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p)
      return not p:isNude() and not table.contains(data:getAllTargets(), p.id) end), function(p) return p.id end)
    if #targets == 0 then return end
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#joyex__qizhi-choose:::"..data.card:getTypeString(), joyex__qizhi.name, true)
    if #tos > 0 then
      event:setCostData(self, tos[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@joyex__qizhi-turn", 1)
    local to = room:getPlayerById(event:getCostData(self))
    local id = room:askForCardChosen(player, to, "he", joyex__qizhi.name)
    local type = Fk:getCardById(id).type
    room:throwCard({id}, joyex__qizhi.name, to, player)
    if type == data.card.type and not player.dead then
      player:drawCards(1, joyex__qizhi.name)
    elseif type ~= data.card.type and not to.dead then
      to:drawCards(1, joyex__qizhi.name)
    end
  end,
})

return joyex__qizhi